function points=ElixhauserPointSystemCox(elix,y,censorvec,alpha)


%%%%%
% This aggregates the 30 Elixhauser comorbidities into a point for a particular choice of survival time (e.g., 1-year survival).
% 
% Input:
% elix - Nx30 matrix containing binary Elixhauser comorbidities, where N is the number of subjects.
% y - column vector containing survival time, should correspond to the rows in elix.
% censorvec - boolean column vector indicating right-censorship; 0 = not censored, 1 = right-censored. Should correspond to the elements in y.
% alpha - statistical significance level that determines which comorbidities are included in point calculation
%
% Output:
% points - column vector containing points for the corresponding rows in elix.
%
% Written by Joon Lee, 2011
%%%%%


idxincl=1:size(elix,2);
idxincl(all(elix==0) | all(elix==1))=[];
finish=false;

while ~finish && ~isempty(idxincl)
    [b,logl,H,stats]=coxphfit(elix(:,idxincl),y,'censoring',censorvec); 
    p=stats.p;
    idxincl(isnan(p))=[];
    b(isnan(p))=[];
    p(isnan(p))=[];    
    if ~all(p<alpha)
        [C,I]=max(p);
        idxincl(I)=[];        
    else
        finish=true;
    end    
end

points=zeros(size(elix,2),1);
if ~isempty(idxincl)
    points(idxincl)=round(b./min(abs(b)));
end
